﻿using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace TraceThisItem.Domain.Initializers
{
	public class ItemTypeConfiguration : EntityTypeConfiguration<ItemType>
	{
		public ItemTypeConfiguration()
		{
			HasKey(t => t.Id)
			      .Property(t => t.Id)
			   .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

			Property(t => t.Name)
				.HasMaxLength(40)
				.IsRequired()
				.IsUnicode(false);

			HasRequired(it => it.Project)
				.WithMany(project => project.ItemTypes)
				.WillCascadeOnDelete();
            
			HasRequired(it => it.Workflow)
				.WithMany(wf => wf.ItemTypes)
				.WillCascadeOnDelete(false);
		}
	}
}
